package com.project_test.kun.travelling_1st.HomePage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.project_test.kun.travelling_1st.HomePage.category.HomePCarListItem;
import com.project_test.kun.travelling_1st.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 16-8-11.
 */
public class HomePCarListAdapter extends BaseAdapter {
    private Context mContext;
    private List<HomePCarListItem> data;

    public HomePCarListAdapter(Context context, List<HomePCarListItem> data) {
        mContext = context;
        this.data = data;
    }

    @Override
    public int getCount() {
//        return 10;
        return data!=null?data.size():0;
    }

    @Override
    public HomePCarListItem getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if (view == null) {
            view= LayoutInflater.from(mContext).inflate(R.layout.item_activity_home_page_car,viewGroup,false);
            holder =new ViewHolder();
            holder.picture= (ImageView) view.findViewById(R.id.item_picture_homep_car);
            holder.name= (TextView) view.findViewById(R.id.item_name_homep_car);
            holder.brand= (TextView) view.findViewById(R.id.item_brand_homep_car);
            holder.model= (TextView) view.findViewById(R.id.item_model_homep_car);
            holder.price= (TextView) view.findViewById(R.id.item_price_homep_car);
            holder.username= (TextView) view.findViewById(R.id.item_username_homep_car);
            holder.guide= (TextView) view.findViewById(R.id.item_guide_homep_car);
            holder.trans= (TextView) view.findViewById(R.id.item_trans_homep_car);
            view.setTag(holder);
        }else{
            holder= (ViewHolder) view.getTag();
        }
        //绑定数据
        HomePCarListItem listItem = data.get(i);
        Picasso.with(mContext).load(listItem.getPicture()).into(holder.picture);
        holder.name.setText(listItem.getName());
        holder.brand.setText(listItem.getBrand());
        holder.model.setText(listItem.getModel());
        holder.price.setText("￥"+listItem.getPrice()+"/天");
        holder.username.setText(listItem.getUsername());
        if (listItem.getGuide()!=0) {
            holder.guide.setVisibility(View.VISIBLE);
        }
        if (listItem.getTrans()!=0){
            holder.trans.setVisibility(View.VISIBLE);
        }
        return view;
    }
    static class ViewHolder{
//        "id": "1000359",
//                "picture": "http://img1.handybest.com/Uploads/Car/920/16/06/5760d272de333.jpg!phone",
        private ImageView picture;
//                "name": "给你带来不一样的旅程，安全，舒适！！！",
        private TextView name;
//                "brand": "别克",
        private TextView brand;
//                "model": "凯越",
        private TextView model;
//                "price": "500.00",
        private TextView price;
//                "username": "恒远诚兴",
        private TextView username;
//                "guide": "0",
        private TextView guide;
//                "trans": "1"
        private TextView trans;

    }
}
